/*
 * @Author: dvlproad
 * @Date: 2022-12-27 18:42:49
 * @LastEditors: dvlproad
 * @LastEditTime: 2023-10-31 19:53:33
 * @Description: 
 */

import 'package:app_common_js_collect_demo/base/UrlPath.dart';
import 'package:flutter/material.dart';

import 'package:flutter_foundation_base/flutter_foundation_base.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'package:event_bus/event_bus.dart';

import 'shared_webview/ts_web_addto_diffpage.dart';
import 'shared_webcontroller/test_web_share_controller_page.dart';

class EventBusUtil {
  static EventBus eventBus = EventBus();
}

class ShareWebControllerShowStateEvent {
  final bool show;
  ShareWebControllerShowStateEvent({required this.show});
}

class ShareWebViewController {
  static WebViewController? webController;
  static WebViewWidget? webViewWidget;
  static List<String>? javaScriptChannelNames;

  static goTSWebViewJSPage(BuildContext context,
      {Map<String, dynamic>? urlParams, int? methodTpye}) {
    // JSUtil.deleteAllCacheData(); // 清除web缓存
    String url = UrlPath.gameUrl;
    // Map<String, dynamic> paramsMap = {
    //   "title": "测试小程序",
    //   "randomNum": 000,
    // };
    if (urlParams != null) {
      url = WebUrlUtil.addH5CustomParams(url, urlParams);
    }
    debugPrint("测试js的网页地址url=$url");

    Navigator.push(context, MaterialPageRoute(
      builder: (context) {
        if (methodTpye == 0) {
          return TSWebAddToDiffPage(
            url: url,
            shouldHideNavBar: false,
            webViewWidget: ShareWebViewController.webViewWidget,
            webController: ShareWebViewController.webController,
            onWebViewCreated:
                (WebViewWidget webViewWidget, WebViewController webController) {
              ShareWebViewController.webViewWidget = webViewWidget;
              ShareWebViewController.webController = webController;
            },
          );
        } else {
          return TestShareWebControllerPage(
            url: url,
            shouldHideNavBar: false,
            webController: ShareWebViewController.webController,
            onWebViewCreated: (WebViewController webController) {
              ShareWebViewController.webController = webController;
            },
          );
        }
      },
    ));
  }
}
